local xibao = fk.CreateSkill {
  name = "lvshi__xibao",
}

Fk:loadTranslationTable{
  ["lvshi__xibao"] = "析报",
  [":lvshi__xibao"] = "当你需要使用基本牌时（每种牌名每回合限一次），你可将至多两张手牌移出游戏直到回合结束，然后令一名其他角色弃置你的一张手牌，视为你使用此基本牌。",
  ["#lvshi__xibao"] = "析报：将至多两张手牌移出游戏，视为使用一张基本牌",
  ["$lvshi__xibao"] = "析报",
  ["#lvshi__xibao-target"] = "请选择一名其他角色弃置你一张手牌",

  ["$lvshi__xibao1"] = "攻如叠浪，前击方止而后击已至！",
  ["$lvshi__xibao2"] = "战无可当，力陷深垒而坚城弗立！",
}
local ls = require "packages/lvshi/utility"
xibao:addEffect("viewas", {
  pattern = ".|.|.|.|.|basic",
  prompt = "#lvshi__xibao",
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("b")
    local names = player:getViewAsCardNames(xibao.name, all_names, nil, player:getTableMark("ls__xibao-turn"))
    if #names == 0 then return end
    return UI.CardNameBox {choices = names, all_names = all_names}
  end,
  card_filter = function (self, player, to_select, selected)
    return #selected < 2 and table.contains(player:getCardIds("h"), to_select)
  end,
  view_as = function(self, player, cards)
    if not self.interaction.data or #cards == 0 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = xibao.name
    card:addFakeSubcards(cards)
    return card
  end,
  before_use = function (self, player, use)
    player.room:addTableMark(player, "ls__xibao-turn", use.card.trueName)
    player:addToPile("$lvshi__xibao", use.card.fake_subcards, false, xibao.name)
    if player:isKongcheng() then return xibao.name end
    local to = player.room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = player.room:getOtherPlayers(player),
      skill_name = xibao.name,
      prompt = "#lvshi__xibao-target",
      cancelable = false,
    })
    if #to > 0 then
      if not player:isKongcheng() then
        local cid = player.room:askToChooseCard(to[1],
        { target = player, flag = "h", skill_name = xibao.name })
        player.room:throwCard({cid}, xibao.name, player, to[1])
      end
    else
      return xibao.name
    end
  end,
  enabled_at_play = function(self, player)
    return not player:isNude()
  end,
  enabled_at_response = function(self, player, response)
    return not response and not player:isNude() and
      #player:getViewAsCardNames(xibao.name, Fk:getAllCardNames("b"), nil, player:getTableMark("ls__xibao-turn"))
  end,
})

xibao:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return not player.dead and #player:getPile("$lvshi__xibao") > 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("$lvshi__xibao"), Player.Hand, player, fk.ReasonJustMove, xibao.name)
  end,
})

return xibao
